#!/usr/bin/env python3
# -*- coding: utf-8 -*-


from dragon.selector import Selector
from dragon.page import DraPage
from pages.calendar import Calendar

class MainForceSe:
    searchInput=Selector('[placeholder=请输入股票代码或名称]','搜索框')
    stockBlock=Selector('li.infinite-list-item','股票展示块')
    stockName=Selector('.item-name>.cp','股票名称')
    stockCode=Selector('.item-name[style="color: rgb(136, 136, 136);"]','股票代码')
    noDataAlert=Selector('div.empty-text','空数据提示')
    startDateButton=Selector('.change-count-start>>.time-text','开始日期按钮')
    endDateButton=Selector('.change-count-end>>.time-text','结束日期按钮')
    changeSortButton=Selector('text=次数','异动次数排序按钮')
    changeCount=Selector('div.item-count','异动次数')
    changeSortIcon=Selector('.ph-icon.fs14>use','排序图标')
    
class MainForcePage:
    def __init__(self, draPage: DraPage):
        self.draPage=draPage
        self.searchInput = draPage.locator(MainForceSe.searchInput)
        self.stockBlock = draPage.locator(MainForceSe.stockBlock)
        self.stockName = draPage.locator(MainForceSe.stockName)
        self.stockCode = draPage.locator(MainForceSe.stockCode)
        self.noDataAlert = draPage.locator(MainForceSe.noDataAlert)
        self.startDateButton = draPage.locator(MainForceSe.startDateButton)
        self.endDateButton = draPage.locator(MainForceSe.endDateButton)
        self.changeSortButton = draPage.locator(MainForceSe.changeSortButton)
        self.changeCount = draPage.locator(MainForceSe.changeCount)
        self.changeSortIcon = draPage.locator(MainForceSe.changeSortIcon)

    def pick_start_date_by_index(self,index:int):
        self.startDateButton.click()
        calendar=Calendar(self.draPage)
        calendar.pick_date_by_index(index)

    def pick_end_date_by_index(self,index:int):
        self.endDateButton.click()
        calendar=Calendar(self.draPage)
        calendar.pick_date_by_index(index)